package gdconf

import (
	"server_cluster/common/logger"
)

// 鱼配置表

// 鱼类概率权重提升类型
const (
	FishWeightUpTypeRarity = 1 // 指定稀有度提升
	FishWeightUpTypeId     = 2 // 指定id提升
)

type FishConfig struct {
	FishId int32 `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 鱼id
	MinLen int32 `csv:"LenMin,omitempty"`                          // 最小长度
	MaxLen int32 `csv:"LenMax,omitempty"`                          // 最大长度
	Rarity int32 `csv:"Rarity,omitempty"`                          // 稀有度
}

func (f *FishConfig) TableName() string {
	return "config_fish"
}

func (g *GameDataConfig) saveFishConfig() {
	saveTableToDb[FishConfig](g.Db, readTable[FishConfig](g.CsvPathPrefix+"Fish.csv"))
}

func (g *GameDataConfig) loadFishConfig() {
	g.GameDataMaps.FishConfigMap = make(map[int32]*FishConfig)
	for _, fishConfig := range loadTableFromDb[FishConfig](g.Db) {
		g.GameDataMaps.FishConfigMap[fishConfig.FishId] = fishConfig
	}
	logger.Info("FishConfig Count: %v", len(g.GameDataMaps.FishConfigMap))
}

func GetFishConfig(fishId int32) *FishConfig {
	value, exist := CONF.GameDataMaps.FishConfigMap[fishId]
	if !exist {
		logger.Error("[ConfigNotFound] FishConfig, fishId: %v", fishId)
		return nil
	}
	return value
}

func GetFishConfigMap() map[int32]*FishConfig {
	return CONF.GameDataMaps.FishConfigMap
}
